﻿using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;


namespace SilverlightHVP.ViewModel
{

   public class TopicsViewModel : INotifyPropertyChanged
   {
      private State state;

      public ObservableCollection<Topic> Topics
      {
          get { return state.Topics; }
      }


      public Topic CurrentTopic
      {
         get { return state.CurrentTopic; }
         set
         {
            state.CurrentTopic = value;
            NotifyPropertyChanged( "CurrentTopic" );
         }
      }



      public TopicsViewModel( State state )
      {
         this.state = state;
         this.state.CurrentItemChanged +=
            new State.CurrentItemChangedHandler( CurrentItemChanged );
         this.state.StateChanged += new State.StateChangedHandler( StateChanged );
         NotifyPropertyChanged( "Topics" );
      }

      void StateChanged( object sender, EventArgs e )
      {
         NotifyPropertyChanged( "Topics" );
      }

      void CurrentItemChanged( object sender, EventArgs e )
      {
         NotifyPropertyChanged( "Topics" );
      }



      public event PropertyChangedEventHandler PropertyChanged;
      private void NotifyPropertyChanged( string propName )
      {
         if ( PropertyChanged != null )
         {
            PropertyChanged( this, new PropertyChangedEventArgs( propName ) );
         }
      }
   }
}
